********************************************************************************
* appendix table 4: unit characteristics regressions

********************************************************************************

cd "$main_dir/data"

* near-far changes in bedroom or bathroom counts, no listing controls

{

local max_dist 600
local iso_dist 250
local g g

use near_far_m`max_dist'_i`iso_dist'_`g',clear

gen treated_after_near=(listing_year>=building_built*l250)

egen ring_fe=group(building_id l250)
gen zero=0

** Panel A, Column 1, listing bedroom counts near-far DD est **
reghdfe listing_bedroom treated_after_near /// 
	if building_sample==1 &  tx250_min_number>0 & tx256_min_number>0 ///
	[aweight=building_sample_weight] ,absorb(ring_fe building_id_year) vce(cl building_id)
	
* Means *
summ listing_bedroom [aweight=building_sample_weight] if e(sample)==1


** Panel B, Column 1, listing bathroom counts near-far DD est **
reghdfe listing_bathroom treated_after_near /// 
	if building_sample==1 &  tx250_min_number>0 & tx256_min_number>0 ///
	[aweight=building_sample_weight] ,absorb(ring_fe building_id_year) vce(cl building_id)

* Means *
summ listing_bathroom [aweight=building_sample_weight] if e(sample)==1	

}

* near-near changes in bedroom or bathroom counts, no listing controls 

{

local max_dist 250
local iso_dist 250
local g g

use near_near_m`max_dist'_i`iso_dist'_`g',clear	

drop if inlist(msa, "dc", "sf")>0
gen zero=0
gen treated=sample
gen treated_after=treated*(listing_year>=building_built)
gen gap=listing_year-building_built
gen treatment=(building_built<2018)*(listing_year>=building_built)

** Panel A, Column 2, listing bedroom counts near-near DD est **
reghdfe listing_bedroom treatment /// 
	if building_sample==1 & min_number>0  ///
	[aweight=building_sample_weight],absorb(msa_year building_id) vce(cl building_id)
	
* Means *
summ listing_bedroom [aweight=building_sample_weight] if e(sample)==1	

** Panel B, Column 2, listing bathroom counts near-near DD est **
reghdfe listing_bathroom treatment /// 
	if building_sample==1 & min_number>0  ///
	[aweight=building_sample_weight],absorb(msa_year building_id) vce(cl building_id)
	
* Means *
summ listing_bathroom [aweight=building_sample_weight] if e(sample)==1
	
}

* DDD changes in bedroom and bathroom counts

local max_dist 600
local iso_dist 250
local g g

use triple_diff_m`max_dist'_i`iso_dist'_g,clear

drop if inlist(msa, "dc","sf")>0
drop if listing_year==2012
egen ring_fe=group(building_id l250)

gen after=(listing_year>=building_built)
replace after = 1 if listing_year>2014 & sample==0
gen after_250_treated=(sample==1 & l250==1 & listing_year>=building_built)

** Panel A, Column 3, listing bedroom counts DDD est **
reghdfe listing_bedrooms sample l250 sample#l250 listing_year#l250 after_250_treated  ///
	if building_sample==1 & tx250_min_number>0 & tx256_min_number>0  ///
	[aweight=building_sample_weight],absorb(ring_fe building_id_year) vce(cl building_id)
* Means *
summ listing_bedrooms [aweight=building_sample_weight] if e(sample)==1	

** Panel B, Column 3, listing bathroom counts DDD est **
reghdfe listing_bathrooms sample l250 sample#l250 listing_year#l250 after_250_treated  ///
	if building_sample==1 & tx250_min_number>0 & tx256_min_number>0  ///
	[aweight=building_sample_weight],absorb(ring_fe building_id_year) vce(cl building_id)
* Means *
summ listing_bathrooms [aweight=building_sample_weight] if e(sample)==1

tab treated if building_tag==1 & building_sample==1 & tx250_min_number>0 & tx256_min_number>0

* near-far changes in listing counts

{

* event studies 250
local max_dist 600
local iso_dist 250
local g g

use near_far_m`max_dist'_i`iso_dist'_`g' if building_sample==1,clear

gen listing_counter=1

gen treated_after_near=(listing_year>=building_built*l250)

egen msa_year=group(msa listing_year)

collapse (sum) listing_counter, by(treated_after_near listing_year building_built l250 building_id tx_n3 tx_n2 tx_0 tx_1 tx_2 tx_3 building_sample_weight msa_year building_id_year tx256_min_number tx250_min_number)

egen ring_fe=group(building_id l250)
gen zero=0

reghdfe listing_counter tx_n3 tx_n2 zero tx_0 tx_1 tx_2 tx_3 if tx250_min_number>0 & tx256_min_number>0 [aweight=building_sample_weight], absorb(ring_fe building_id msa_year) vce(cl building_id)

** Panel C, Column 1, listing counts near-far DD est **
reghdfe listing_counter treated_after_near if tx250_min_number>0 & tx256_min_number>0 [aweight=building_sample_weight] ,absorb(ring_fe building_id msa_year) vce(cl building_id)

* Means *
summ listing_counter [aweight=building_sample_weight] if e(sample)==1
	
}

* near-near changes in listing counts

{

local max_dist 250
local iso_dist 250
local g g

use near_near_m`max_dist'_i`iso_dist'_`g' if building_sample==1,clear	

drop if inlist(msa, "dc", "sf")>0
gen zero=0
gen treated=sample
gen treated_after=treated*(listing_year>=building_built)
gen gap=listing_year-building_built

gen treatment=(building_built<2018)*(listing_year>=building_built)

gen listing_counter=1

collapse (sum) listing_counter, by(treatment listing_year building_built building_id tx_n3 tx_n2 zero tx_0 tx_1 tx_2 tx_3 building_sample_weight msa_year min_number)

** Panel C, Column 2, listing counts near-near DD est **
reghdfe listing_counter treatment /// 
	if min_number>0  ///
	[aweight=building_sample_weight],absorb(msa_year building_id) vce(cl building_id)

* Means *
summ listing_counter [aweight=building_sample_weight] if e(sample)==1
	
}

* DDD changes in listing counts

use triple_diff_m600_i250_g,clear

drop if inlist(msa, "dc","sf")>0
drop if listing_year==2012
egen ring_fe=group(building_id l250)

gen after=(listing_year>=building_built)
replace after = 1 if listing_year>2014 & sample==0
gen after_250_treated=(sample==1 & l250==1 & listing_year>=building_built)

gen listing_counter=1

collapse (sum) listing_counter, by(after_250_treated listing_year building_built building_id building_id_year l250 sample ring_fe building_sample building_sample_weight msa_year tx250_min_number tx256_min_number)

** Panel C, Column 3, listing counts near-near DD est **	
reghdfe listing_counter sample l250 sample#l250 listing_year#l250 after_250_treated ///
	if building_sample==1 & tx250_min_number>0 & tx256_min_number>0  ///
	[aweight=building_sample_weight],absorb(ring_fe building_id_year) vce(cl building_id)
	
* Means *
summ listing_counter [aweight=building_sample_weight] if e(sample)==1
	


